package com.appbee.user.server.service;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Provider;

import com.appbee.core.server.requestfactory.BaseService;
import com.appbee.user.server.dao.AccessControl;
import com.appbee.user.server.dao.MemberDAO;
import com.appbee.user.server.model.Member;
import com.appbee.user.server.model.WebUser;

public class MemberService extends BaseService<Member,MemberDAO>
{
	private final Provider<AccessControl> accessControlProvider;
	
	@Inject
	public MemberService(Provider<AccessControl> accessControlProvider)
	{
		this.accessControlProvider = accessControlProvider;
	}

	public List<Member> findByRange(int start,int size)
	{
		List<Member> list = daoProvider.get().findByRange(start, size);
		return list;
	}
	
	public Integer totalSize()
	{
		return daoProvider.get().totalSize();
	}
	
	public Member findById(long id)
	{
		return daoProvider.get().findById(id);
	}
	
	public Member save(Member bean)
	throws Exception
	{
		daoProvider.get().saveAllTransaction(bean);
		return bean;
	}
	
	public List<Member> removeAndFindByRange(Member bean,int start,int size)
	{
		daoProvider.get().delete(bean);
		return findByRange(start, size);
	}

	public WebUser getCurrentUser(String destinationURL)
	{
		return accessControlProvider.get().getCurrentUser(destinationURL);
	}
}
